home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
vb022e
/
vb022ex.bas
< prev
next >
Wrap
BASIC Source File
|
1995-09-06
|
9KB
|
264 lines
Sub CustomMsg (Message As String, IconNumber As Integer, MsgTitle As String, BoxWidth As Integer, BtnEnabled As Integer)
Load MsgForm
MsgForm.WindowState = 0
MsgForm.Visible = 0
If MsgTitle <> "" Then MsgForm.Caption = MsgTitle Else MsgForm.Caption = ""
'SET WIDTH OF FORM
If BoxWidth <> 0 Then
MsgForm.width = BoxWidth
Else
MsgForm.width = 4545
End If
'GET ICON: LOAD ICONNUMBER INTO TAG & SHOW IF SUCCESSFUL...
If IconNumber > 0 Then
On Error Resume Next
MsgForm.picIcon(0).picture = MsgForm.picIcon(IconNumber).picture
If Err Then
MsgForm.picIcon(0).Visible = 0
MsgForm.picIcon(0).Tag = "0"
Else
MsgForm.picIcon(0).Visible = -1
MsgForm.picIcon(0).Tag = Format$(IconNumber, "0")
End If
On Error GoTo 0
Else
MsgForm.picIcon(0).Visible = 0
MsgForm.picIcon(0).Tag = "0"
End If
'POSITION, SIZE, ALIGN MESSAGE LABEL...
MsgForm.LblMsg.Alignment = 0
If MsgForm.picIcon(0).Tag <> "0" Then 'ICON SPECIFIED, LOADED...
MsgForm.LblMsg.left = (MsgForm.picIcon(0).left + MsgForm.picIcon(0).width + 120)
MsgForm.LblMsg.width = MsgForm.ScaleWidth - (MsgForm.picIcon(0).width) - (MsgForm.picIcon(0).left * 2) - 120
Else
MsgForm.LblMsg.left = MsgForm.picIcon(0).left
MsgForm.LblMsg.width = MsgForm.ScaleWidth - (MsgForm.LblMsg.left * 2)
End If
'Get text in there!
Result% = WrapText(Message, MsgForm, MsgForm.LblMsg)
' make icon picture borderless
MsgForm.picIcon(0).BorderStyle = 0
' center Icon vertically next to label with message text
If MsgForm.LblMsg.height > MsgForm.picIcon(0).height Then ' MESSAGE TALLER THAN ICON
MsgForm.picIcon(0).top = MsgForm.LblMsg.top + (MsgForm.LblMsg.height / 2) - (MsgForm.picIcon(0).top / 2) - (MsgForm.picIcon(0).height / 2)
Else 'ICON TALLER THAN MESSAGE.
MsgForm.LblMsg.top = MsgForm.picIcon(0).top + (MsgForm.picIcon(0).height / 2) - (MsgForm.LblMsg.top / 2) - (MsgForm.LblMsg.height / 2)
End If
HOffSet% = MsgForm.height - MsgForm.scaleheight
' Modal with OK button or not?
If BtnEnabled Then
MsgForm.btnOk.top = MsgForm.LblMsg.top + MsgForm.LblMsg.height + 120
MsgForm.btnOk.left = (MsgForm.ScaleWidth - MsgForm.btnOk.width) / 2
MsgForm.btnOk.Visible = -1
MsgForm.height = MsgForm.btnOk.top + MsgForm.btnOk.height + HOffSet% + 120
Else
MsgForm.btnOk.Visible = 0
MsgForm.height = MsgForm.LblMsg.top + MsgForm.LblMsg.height + HOffSet% + 120
End If
' Centers message on the screen, but you can change this if you wish!
MsgForm.left = (Screen.width - MsgForm.width) / 2
MsgForm.top = (Screen.height - MsgForm.height) / 2
MsgForm.btnOk.Caption = "OK"
If BtnEnabled Then
MsgForm.Show MODAL
Else
MsgForm.Show
End If
End Sub
Function WrapText (SourceTxt As String, DestForm As Form, DestCtrl As Control) As Integer
' SourceTxt is a string containing text to wrap.
' DestCtrl is the control to put the text in.
' DestForm is the the form the control is on.
'This function copies the text to the destination,
'using different techniques based on the type of control passed.
'ASSUMPTION IS the Width of the destination control
'is set and that it's height can be varied.
Dim LF As String
LF = Chr$(13) + Chr$(10)
'save these.
SavedFontName$ = DestForm.Fontname
SavedFontSize% = DestForm.FontSize
SavedFontBold% = DestForm.FontBold
SavedFontItal% = DestForm.FontItalic
If TypeOf DestCtrl Is Picturebox Then
SavedScaleMode% = DestForm.DestCtrl.ScaleMode
End If
'the form font properties should match
'the DestCtrl control's font properties for
'TextHeight/Width to work.
DestForm.Fontname = DestCtrl.Fontname
DestForm.FontSize = DestCtrl.FontSize
DestForm.FontItalic = DestCtrl.FontItalic
DestForm.FontBold = DestCtrl.FontBold
ReDim CreatedTxt(100) As String
SourceLength% = Len(SourceTxt)
LineQty% = 0
StartPlc% = 1
'******** HERE'S THE LOOP TO SPLIT THE LINES***********************************
'******** AND LOAD THEM INTO AN ARRAY OF STRINGS.*******************************
Do
SpaceLoc% = InStr(StartPlc%, SourceTxt, " ")
LFLoc% = InStr(StartPlc%, SourceTxt, LF)
If SpaceLoc% = 0 And LFLoc% = 0 Then
NextWord$ = Mid$(SourceTxt, StartPlc%)
ElseIf SpaceLoc% <> 0 And LFLoc% = 0 Then
NextWord$ = Mid$(SourceTxt, StartPlc%, SpaceLoc% - StartPlc% + 1)
ElseIf SpaceLoc% = 0 And LFLoc% <> 0 Then
NextWord$ = Mid$(SourceTxt, StartPlc%, LFLoc% - StartPlc% + 2)
ElseIf SpaceLoc% <> 0 And LFLoc% <> 0 Then
'which comes first? Space or LF?
If SpaceLoc% < LFLoc% Then 'Space came first...
NextWord$ = Mid$(SourceTxt, StartPlc%, SpaceLoc% - StartPlc% + 1)
Else
NextWord$ = Mid$(SourceTxt, StartPlc%, LFLoc% - StartPlc% + 2)
End If
End If
TabLoc% = InStr(NextWord$, Chr$(9))
If TabLoc% <> 0 Then
Lft$ = Left$(NextWord$, InStr(NextWord$, Chr$(9)) - 1)
Rit$ = Mid$(NextWord$, InStr(NextWord$, Chr$(9)) + 1)
NextWord$ = Lft$ + Space$(gTabSize) + Rit$
DebugMsg$ = DebugMsg$ + "TAB Found at " + Format$(TabLoc%, "0") + LF
End If
WordLen% = Len(NextWord$)
DebugMsg$ = DebugMsg$ + "Word found is [" + NextWord$ + "]" + LF
DebugMsg$ = DebugMsg$ + "Word Length is " + Format$(WordLen%) + LF
If DestForm.TextWidth(CreatedTxt(LineQty%) + NextWord$) > DestCtrl.width Then
LineQty% = LineQty% + 1
End If
CreatedTxt(LineQty%) = CreatedTxt(LineQty%) + NextWord$
StartPlc% = StartPlc% + WordLen%
If StartPlc% >= SourceLength% Then Exit Do
Loop
If TypeOf DestCtrl Is Listbox Then GoSub FillList
If TypeOf DestCtrl Is ComboBox Then GoSub FillList
If TypeOf DestCtrl Is Label Then GoSub FillLabel
If TypeOf DestCtrl Is TextBox Then GoSub FillText
If TypeOf DestCtrl Is Picturebox Then GoSub PrintPic
'restore form's font properties
DestForm.Fontname = SavedFontName$
DestForm.FontSize = SavedFontSize%
DestForm.FontBold = SavedFontBold%
DestForm.FontItalic = SavedFontItal%
If TypeOf DestCtrl Is Picturebox Then DestCtrl.ScaleMode = SavedScaleMode%
WrapText = -1
Exit Function
'-------------------------- SUBROUTINES-----------------------------
FillList:
Counter% = 0
DestCtrl.Visible = 0
x% = DoEvents()
If DestCtrl.Listcount <> 0 Then For R% = 0 To DestCtrl.Listcount - 1: DestCtrl.RemoveItem 0: Next R%
Do
DestCtrl.AddItem CreatedTxt(Counter%), Counter%
Counter% = Counter% + 1
If CreatedTxt(Counter%) = "" Or CreatedTxt(Counter%) = LF Then Exit Do
Loop
DestForm.DestCtrl.Listindex = -1
DestForm.DestCtrl.height = Counter% * DestForm.TextHeight("A")
DestForm.DestCtrl.Visible = -1
DestForm.DestCtrl.Refresh
Return
FillLabel:
Counter% = 0
DestCtrl.Visible = -1
DestCtrl.Caption = ""
Do
If Not InStr(CreatedTxt(Counter%), LF) Then
Temp$ = Temp$ + CreatedTxt(Counter%) + LF
Else
Temp$ = Temp$ + CreatedTxt(Counter%)
End If
Counter% = Counter% + 1
If CreatedTxt(Counter%) = "" Then Exit Do
Loop
Counter% = Counter% + 1
DestCtrl.Caption = Temp$
'Remove Trailing Line feeds...
While Right$(DestCtrl.Caption, 2) = LF
DestCtrl.Caption = Left$(DestCtrl.Caption, Len(DestCtrl.Caption) - 2)
Wend